package com.sunxueqi.project.system.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sunxueqi.framework.web.controller.BaseController;
import com.sunxueqi.framework.web.vo.ResponseData;
import com.sunxueqi.project.system.service.ILinkService;
import com.sunxueqi.project.system.vo.Link;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;

@Api(tags="友情链接")
@RestController
@RequestMapping("/system/link")
public class LinkController extends BaseController {
	
	@Autowired
	private ILinkService linkService;
	
	/**
	 * 获取所有的友情链接
	 * @param link
	 * @return
	 */
	@GetMapping("/list")
	public ResponseData list(Link link) {
		startPage();
		List<Link> list = linkService.selectLinkList(link);
		return ResponseData.successTableData(list);
	}
	
	/**
	 * 新增友情链接
	 * @param link
	 * @return
	 */
	@PostMapping
	public ResponseData add(@RequestBody Link Link) {
		return super.getResponseDataRow(linkService.add(Link));
	}
	
	/**
	 * 删除友情链接
	 * @param ids
	 * @return
	 */
	@DeleteMapping("/{ids}")
	public ResponseData delete(@PathVariable String ids) {
		String [] idArray = StrUtil.split(ids, ",");
		return super.getResponseDataRow(linkService.deleteLinkByIds(idArray));
	}
	
	/**
	 * 修改友情链接
	 * @param link
	 * @return
	 */
	@PutMapping
	public ResponseData update(@RequestBody Link Link) {
		return super.getResponseDataRow(linkService.updateLink(Link));
	}
	
	/**
	 * 修改友情链接
	 * @param link
	 * @return
	 */
	@PutMapping("/changeStatus")
	public ResponseData changeStatus(@RequestBody Link Link) {
		return getResponseDataRow(linkService.changeStatus(Link));
	}
	

}
